package net.starwifi.duobao.web.dMember;

import net.starwifi.duobao.entity.DBOrder;
import net.starwifi.duobao.entity.Member;
import net.starwifi.duobao.mvc.*;
import net.starwifi.duobao.service.DBOrderService;
import net.starwifi.duobao.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ruoo on 16/1/10.
 */
@Controller("wapDMemberRecordController")
@RequestMapping("/dMember")
public class DMemberRecordController extends BaseController {

    @Autowired
    MemberService memberService;

    @Autowired
    DBOrderService dbOrderService;

    /**
     * 用户购买记录
     */
    @RequestMapping(value = "/record", method = RequestMethod.GET)
    public String db(Model model) {
        Member member = memberService.getCurrent();
        PageView pageView = new PageView(0, 10);
        pageView.addOrder(net.starwifi.duobao.mvc.Order.desc("id"));
        pageView.addFilter(Filter.eq("paymentStatus", 1));
        pageView.addFilter(Filter.eq("memberId", member.getId()));
        Page<DBOrder> page = dbOrderService.getScrollData(pageView);
        model.addAttribute("orderList", page.getContent());
        model.addAttribute("member", member);
        return "/dMember/record";
    }

    @RequestMapping(value = "/record-content", method = RequestMethod.GET)
    public String dbTimesRecordContent(Model model, int pageNum) {
        Member member = memberService.getCurrent();
        PageView pageView = new PageView(pageNum, 10);
        pageView.addOrder(net.starwifi.duobao.mvc.Order.desc("id"));
        pageView.addFilter(Filter.eq("paymentStatus", 1));
        pageView.addFilter(Filter.eq("memberId", member.getId()));
        Page<DBOrder> page = dbOrderService.getScrollData(pageView);
        model.addAttribute("orderList", page.getContent());
        model.addAttribute("member", member);
        return "/dMember/record-content";
    }


}
